
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@poppinss/config
Advanced tools
Extremely simple module to decouple application config from the file system, which has handful of benefits.
Install the package from npm as follows
npm i @poppinss/config
# yarn
yarn add @poppinss/config
and then use the class as follows:
import { Config } from '@poppinss/config'
const initialConfiguration = {
app: {
name: 'adonis',
},
database: {
connection: 'mysql',
},
logger: {
level: 'debug',
},
}
const config = new Config(initialConfiguration)
config.get('app.name') // adonis
config.get('database.connection') // mysql
config.get('database.user', 'root') // root
Majority of projects create config files next to the source files or inside a dedicated config directory and require those files wherever needed.
However, with AdonisJs, we make the process of config management a little bit better over manually requiring config files and it has handful of benefits.
AdonisJs recommends to save all configuration inside the config
directory and then behind the scenes it read those files and feed it's content to the Config
class and later the application developer can get rid of importing config files and rely on the Config
class instance instead.
We virtually decouple the config from the filesystem, which means your app can read the configuration from anywhere and pass it to the Config
class. For example:
const { db } from 'some-db-module'
import { Config } from '@poppinss/config'
const settings = await db.table('settings').select('*')
const config = new Config({}) // start with empty store
settings.forEach((row) => {
config.set(row.key, JSON.parse(row.value))
})
Now since, you are not requiring the config files directly inside your application code, you can easily provide fake values during tests.
export const db = {
connection: 'pg'
}
import { Config } from '@poppinss/config'
import { db } from './config/database'
export default new Config({ db })
import { Db } from 'some-db-module'
import config from './config'
const db = new Db(config.get('db'))
class UserController {
async store () {
// perform insert
}
}
import config from './config'
config.set('db.connection', 'sqlite')
// now run tests and connection will be sqlite over pg
Reading nested values in Javascript isn't fun. You have to ensure that top level object is actually an object before accessing it's child.
However, with this module, you can pull nested values without worrying about the intermediate parents being undefined
or null
.
config.get('database.mysql.connection.host', '127.0.0.1')
The get
method will return 127.0.0.1
if any of the parents or the value of host
itself is non-existent.
Following are the autogenerated files via Typedoc
FAQs
Config management for Adonis framework
The npm package @poppinss/config receives a total of 2 weekly downloads. As such, @poppinss/config popularity was classified as not popular.
We found that @poppinss/config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.